package threading;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo17 {
    public static void main(String[] args) throws InterruptedException {
        //BlockingDeque<String> queue = new ArrayBlockingQueue<>();//基于数组
        BlockingDeque<String> queue= new LinkedBlockingDeque<>();//基于链表
        //阻塞队列核心方法，主要有两个
        //1.put 入队列
        queue.put("hello1");
        queue.put("hello2");
        queue.put("hello3");
        queue.put("hello4");
        queue.put("hello5");
        //2.take 出队列
        String result = null;
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
    }
}
